//
//  iphoneViewController.m
//  tongxunlu
//
//  Created by mac on 15-11-16.
//  Copyright (c) 2015年 yb. All rights reserved.
//

#import "iphoneViewController.h"
#import "ViewController.h"
#import "tel-phoneViewController.h"

@interface iphoneViewController ()
{
    NSArray *date;
    NSArray *number;
    NSArray *header;
}
@end

@implementation iphoneViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    date = @[
             @[@"安娜",@"安信"],
             @[@"百合",@"白山"],
             @[@"蔡伦",@"彩家"],
             @[@"戴家",@"德白"],
             @[@"阿康",@"尔泰"],
             ];
    
    number = @[
               @"1",
               @"2",
               @"3",
               @"4",
               @"5",
               ];
    header = @[
               @"A",
               @"B",
               @"C",
               @"D",
               @"E",
               ];
    self.title = @"第二标题界面";
    //在标题栏上出现编辑的按钮
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return date.count;
}

//计算数组里面的单位
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [date[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //表格的布局
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    //表格的设置
    cell.textLabel.text = date[indexPath.section][indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    
    
    
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return header[section];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //渐变
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //创建下一个界面
    ViewController *con = [ViewController new];
    
    //点击
    [self.navigationController pushViewController:con animated:YES]; 
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [b addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
    [self .view addSubview:b];
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    //移动
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    //移动的次数  空
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    //删除操作
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSMutableArray *arr = date.mutableCopy;
        NSMutableArray *inArr = [date[indexPath.section]mutableCopy];
        [inArr removeObjectAtIndex:indexPath.row];
        [arr replaceObjectAtIndex:indexPath.section withObject:inArr];
        date = arr;
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
    }
}

- (void)onClick:(id)sender
{
    tel_phoneViewController *con = [tel_phoneViewController new];
    [self.navigationController pushViewController:con animated:YES];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
